<!-- Tell a friend dialog -->
<div id='tell_friend' style="display:none;">
	<div class='header'><span>Tell a friend</span></div>
	<div class='message'></div>
	
	<div class='buttons'>
		<div id="button_continue" class='continue'>Fortsæt</div> 
		<div id="button_no" class='no simplemodal-close'>Ingen</div>
		<div id="button_yes" class='yes'>Ja</div> 				 
	</div>
	<br/>
</div>         

<div id="osx-modal-content">
    <div id="osx-modal-title">Tip en ven</div>
    <div class="close"><a class="simplemodal-close" href="#">x</a></div>
    <div id="osx-modal-data">  
    	<div id="tell_friend_error" class="errorForm"></div>  
    	<div class="form_levering p15t p12r p15l">     		
        	<div class="float_left">   
        		<form id="tell_friend" action="<?php echo str_replace('&', '&amp;', $action); ?>" method="post" enctype="multipart/form-data">             	
	                <label>Din email*:</label>
	                <input id="email_from" class="txt_levering w270" name="email_from" type="text" />
	                <br class="cb" />
	                <label>Din ven email*:</label>
	                <input id="email_to" class="txt_levering w270" name="email_to" type="text" />
	                <br class="cb" />    
					<label>Besked: </label>
                    <textarea id="tf_message" class="txt_levering w270" name="message" cols="" rows=""></textarea>
					<br class="cb" />            
	                <label>&nbsp;</label>					
	                <input id="send_email" name="send" type="image" src="catalog/view/theme/<?php echo $template; ?>/images/bt_send.png" /> 
            		<input id="reset_value" name="reset" type="image" src="catalog/view/theme/<?php echo $template; ?>/images/bt_nulstil.png" />					
            	</form>
            </div>              
            <p class="cb"></p>
    	</div>
    </div>
</div>

<script type="text/javascript">
//<![CDATA[
	//var mail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;   
	var mail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,6})+$/;
	var msg = 'Indtast venligst en gyldig e-mail adresse'; 	
	
	jQuery('a.osx').click(function(){
		var message = 'Jeg fandt dette produkt og tror at det kunne have interesse for dig. \n\n' + window.location.href;
	
		jQuery('#tf_message').val(message);
	});
	
	jQuery('#send_email').click(function(event){
		event.preventDefault();
		var error = false;
		
		if((jQuery('#email_from').val() == '') || !mail_filter.test(jQuery('#email_from').val())){
			error = true;	
			jQuery('#email_from').addClass('errorField'); 				
		}	
		
		if((jQuery('#email_to').val() == '') || !mail_filter.test(jQuery('#email_to').val())){
			error = true;	
			jQuery('#email_to').addClass('errorField');
		}
		   				
		if(error){
			jQuery('#tell_friend_error').html('<h3>' + msg + '</h3>');
		}
		else {
			jQuery('#tell_friend_error').html('');	
			
			jQuery.ajax({
	            type: 'post',
	            url: '<?php echo $send; ?>',
	            dataType: 'html',
	            data: {
					'email_from': jQuery('#email_from').val(), 
					'email_to': jQuery('#email_to').val(), 
					'url': window.location.href,
					'message': jQuery('#tf_message').val()
					//String(document.location).toLowerCase()
				},
	            success: function(html){
	                jQuery('#osx-modal-data .float_left').html('<h3 style="color:#000; font-weight:bold; text-transform:none;">' + html + '</h3>');
	            },    
	            complete: function(){
            	}
	        });    			
		}
	});
	
	jQuery('#reset_value').click(function(event){
		event.preventDefault();
		
		jQuery('#tell_friend input').each(function(){
			jQuery(this).val('');
			if(jQuery(this).hasClass('errorField')){
				jQuery(this).removeClass('errorField');
			}
		});	
		jQuery('#tell_friend_error').html('');	
	});	
//]]>
</script>